﻿CREATE VIEW dbo.v_CollectionInfo
AS
SELECT     CF_E.LoanID, CF_E.[Customer #], CF_E.ApplID, CF_E.SSN, CF_E.VIN, CF_E.[G_L Date], CF_E.[Open Date], CF_E.Name, CF_E.Address, CF_E.City, 
                      CF_E.St, CF_E.[Zip Code], CF_E.[Home Phone #], CF_E.[Work Phone #], CF_E.[Car Year], CF_E.Make, CF_E.Model, CF_E.Mileage, 
                      CF_E.[Pymnt Schedule], CF_E.[# of Payments], CF_E.[Payment Amount], CF_E.[1st_ Payment Date], CF_E.FirstPaymentDateCalc, 
                      CF_E.[Last Payment Date], CF_E.[Next Payment Date], CF_E.[# Pmts Remaining], CF_E.[Status Code], CF_E.Loan#_Comments, CF_E.[Investor Client], 
                      CF_E.[Dealer Code], CF_E.Dealer, CF_E.[Joint Name], CF_E.[Joint Address], CF_E.[Joint City], CF_E.[Joint State], CF_E.[Joint Zipcode], 
                      CF_E.[Joint SSN], CF_E.[Joint H Phone#], CF_E.[Joint W Phone#], CF_E.[Primary Cell#], CF_E.[Joint Cell#], CF_E.[NSF Balance], CF_E.[Late Chg Bal], 
                      CF_E.[Apply Late Fee], CF_E.[Bankruptcy Filed Y_N?], CF_E.[Bankruptcy Type 07_13?], CF_E.[Total Principal], CF_E.DPD, CF_E.DSLP, 
                      CF_E.PaymentsMade, CF_E.[Final Repo Date], CF_E.[Title Received Y_N?], CF_E.[Amt_ Fin__Disc_ Amt], CF_E.[Partial Payment], 
                      CF_E.[# Pmts RemainingM], CF_E.[# of PaymentsM], CF_E.PaymentsMadeM, CF_E.NDay, CF_E.CompanyID_Raw, CF_E.PerDiem, 
                      CF_E.PastDueAmount AS PastDue, usix.v_PaymentDPDs.DPD30, usix.v_PaymentDPDs.DPD60, usix.v_PaymentDPDs.DPD90, CF_E.PayOff_TP, 
                      CF_E.PayOff_Calc, CF_E.StatusID_BuyBack, CF_E.Status_BuyBack, dbo.OffsetDate(CF_E.TimeZoneOffset, GETDATE()) AS LocalTime, CF_E.TimeZone, 
                      CF_E.APR, CF_E.DealerPhone, CF_E.LateCharges, CF_E.LatePmtsCount, ISNULL(CF_E.LateCharges, 0) + ISNULL(CF_E.[Late Chg Bal], 0) 
                      AS LateBalance, CF_E.StatusID_Collection, dbo.t_ADS_Login.DisplayName AS CollectorName, dbo.clr_RegEx_Replace(dbo.t_ADS_Login.DisplayName,
                       N'(\w)(\S+)(.+)', N'$1. $3', - 1, 0, 1) AS CollectorShort, CF_E.UsixID, ISNULL(dbo.t_ADS_Login.Extension, '2071') AS CollectorExtension, 
                      ISNULL(usix.t_Company.FullName, 'AFFILIATED FINANCIAL CORPORATION') AS CompanyFullName, CF_E.NSF_Date, CF_E.NSF_Count, 
                      CF_E.NSF_Amount, CF_E.PastDuePayments, CASE [1st_ Payment Date] WHEN FirstPaymentDateCalc THEN 0 ELSE 1 END AS HasDeferment, 
                      CF_E.CompanyID, CF_E.Status_Collection, CF_E.StatusID_Repo, CF_E.Status_Repo, CF_E.DefermentsCount, CF_E.StatusID_BK
FROM         usix.v_CustomerFile_Export_10 AS CF_E LEFT OUTER JOIN
                      usix.t_Company ON CF_E.CompanyID = usix.t_Company.ID LEFT OUTER JOIN
                      dbo.t_ADS_Login ON CF_E.DateDueBy = dbo.t_ADS_Login.sAMAccountName LEFT OUTER JOIN
                      usix.v_PaymentDPDs ON CF_E.[Customer #] = usix.v_PaymentDPDs.[Id #] AND CF_E.CompanyID = usix.v_PaymentDPDs.CompanyID

GO
EXECUTE sp_addextendedproperty @name = N'MS_DiagramPane1', @value = N'[0E232FF0-B466-11cf-A24F-00AA00A3EFFF, 1.00]
Begin DesignProperties = 
   Begin PaneConfigurations = 
      Begin PaneConfiguration = 0
         NumPanes = 4
         Configuration = "(H (1[39] 4[29] 2[19] 3) )"
      End
      Begin PaneConfiguration = 1
         NumPanes = 3
         Configuration = "(H (1[38] 4[42] 3) )"
      End
      Begin PaneConfiguration = 2
         NumPanes = 3
         Configuration = "(H (1 [50] 2 [25] 3))"
      End
      Begin PaneConfiguration = 3
         NumPanes = 3
         Configuration = "(H (4[30] 2[40] 3) )"
      End
      Begin PaneConfiguration = 4
         NumPanes = 2
         Configuration = "(H (1 [56] 3))"
      End
      Begin PaneConfiguration = 5
         NumPanes = 2
         Configuration = "(H (2 [66] 3))"
      End
      Begin PaneConfiguration = 6
         NumPanes = 2
         Configuration = "(H (4 [50] 3))"
      End
      Begin PaneConfiguration = 7
         NumPanes = 1
         Configuration = "(V (3))"
      End
      Begin PaneConfiguration = 8
         NumPanes = 3
         Configuration = "(H (1[56] 4[18] 2) )"
      End
      Begin PaneConfiguration = 9
         NumPanes = 2
         Configuration = "(H (1[45] 4) )"
      End
      Begin PaneConfiguration = 10
         NumPanes = 2
         Configuration = "(H (1[66] 2) )"
      End
      Begin PaneConfiguration = 11
         NumPanes = 2
         Configuration = "(H (4[60] 2) )"
      End
      Begin PaneConfiguration = 12
         NumPanes = 1
         Configuration = "(H (1) )"
      End
      Begin PaneConfiguration = 13
         NumPanes = 1
         Configuration = "(V (4) )"
      End
      Begin PaneConfiguration = 14
         NumPanes = 1
         Configuration = "(V (2))"
      End
      ActivePaneConfig = 0
   End
   Begin DiagramPane = 
      Begin Origin = 
         Top = 0
         Left = 0
      End
      Begin Tables = 
         Begin Table = "CF_E"
            Begin Extent = 
               Top = 6
               Left = 38
               Bottom = 504
               Right = 237
            End
            DisplayFlags = 280
            TopColumn = 135
         End
         Begin Table = "t_Company (usix)"
            Begin Extent = 
               Top = 372
               Left = 386
               Bottom = 480
               Right = 537
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "t_ADS_Login"
            Begin Extent = 
               Top = 180
               Left = 397
               Bottom = 288
               Right = 563
            End
            DisplayFlags = 280
            TopColumn = 1
         End
         Begin Table = "v_PaymentDPDs (usix)"
            Begin Extent = 
               Top = 11
               Left = 370
               Bottom = 169
               Right = 536
            End
            DisplayFlags = 280
            TopColumn = 0
         End
      End
   End
   Begin SQLPane = 
   End
   Begin DataPane = 
      Begin ParameterDefaults = ""
      End
      Begin ColumnWidths = 81
         Width = 284
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'VIEW', @level1name = N'v_CollectionInfo';


GO
EXECUTE sp_addextendedproperty @name = N'MS_DiagramPane2', @value = N'Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
      End
   End
   Begin CriteriaPane = 
      Begin ColumnWidths = 11
         Column = 9345
         Alias = 1605
         Table = 1170
         Output = 720
         Append = 1400
         NewValue = 1170
         SortType = 1350
         SortOrder = 1410
         GroupBy = 1350
         Filter = 1350
         Or = 1350
         Or = 1350
         Or = 1350
      End
   End
End', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'VIEW', @level1name = N'v_CollectionInfo';


GO
EXECUTE sp_addextendedproperty @name = N'MS_DiagramPaneCount', @value = 2, @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'VIEW', @level1name = N'v_CollectionInfo';

